import 'package:flutter/material.dart';
import '../../l10n/app_localizations.dart';
import '../../models/serach_info_model.dart';
import '../../manger/cached_image_widget.dart';
import '../../mine/controller/set_page.dart';
class SearchNoneView extends StatelessWidget {
  final Function onBack;
  final Function(String) onSearch;
  final Function(int) pushDetail;
  final Function clickCustom;
  final Function(bool) onUnfold;
  final bool isUnfold;
  final TextEditingController _searchController = TextEditingController();
  final List<PageDataListNoModel> noDataList;

  var codeName = "USD"; // 临时默认值

  final String searchKey;

  SearchNoneView({
    Key? key,
    required this.onBack,
    required this.onSearch,
    required this.onUnfold,
    required this.isUnfold,
    required this.clickCustom,
    required this.noDataList,
    required this.pushDetail,
    required this.searchKey,
    TextEditingController? searchController,
  }) : super(key: key) {
    codeName = "USD";
    _searchController.text = searchKey;
  }

@override
Widget build(BuildContext context) {
  return Scaffold(
    resizeToAvoidBottomInset: true,
    body: Container(
      decoration: const BoxDecoration(
        gradient: LinearGradient(
          colors: [Color(0xFFE1ECFE), Color(0xFFE7E5FD), Color(0xFFF8F6F7)],
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
        ),
      ),
      padding: const EdgeInsets.only(left: 0, right: 0, top: 50, bottom: 0),
      child: SingleChildScrollView(
        child: Column(
          children: [
            /// 顶部搜索栏（保留原来的）
            Row(
              children: [
                IconButton(
                  icon: Image.asset('assets/images/leftpush.png', height: 20, width: 20),
                  onPressed: () => onBack(),
                ),
                Expanded(
                  child: Container(
                    height: 40,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(20),
                    ),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Padding(
                          padding: const EdgeInsets.symmetric(horizontal: 10),
                          child: Image.asset('assets/images/serach2.png', width: 16, height: 16),
                        ),
                        Expanded(
                          child: TextField(
                            style: const TextStyle(color: Color(0xFF505050), fontSize: 14, height: 1.2),
                            decoration: InputDecoration(
                              isDense: true,
                              hintText: AppLocalizations.of(context)!.pleaseEnterProductName,
                              hintStyle: const TextStyle(color: Color(0xFFACACAC), fontSize: 14, height: 1.2),
                              border: InputBorder.none,
                              contentPadding: EdgeInsets.zero,
                            ),
                            onSubmitted: (value) => onSearch(value),
                            controller: _searchController,
                          ),
                        ),
                        const SizedBox(width: 5),
                        Container(width: 1, height: 24, color: const Color(0xFFE6E6E6)),
                        TextButton(
                          onPressed: () => onSearch(_searchController.text),
                          child: Text(
                            AppLocalizations.of(context)!.search,
                            style: const TextStyle(color: Colors.blue, fontSize: 14),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                const SizedBox(width: 10),
                TextButton(
                  onPressed: () {
                    onUnfold(!isUnfold);
                  },
                  style: TextButton.styleFrom(
                    backgroundColor: Colors.white,
                    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
                    padding: const EdgeInsets.symmetric(horizontal: 5),
                    fixedSize: const Size(60, 35),
                  ),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Text(
                        codeName,
                        style: const TextStyle(color: Color(0xFF000000), fontSize: 14),
                      ),
                      const SizedBox(width: 2),
                      Image.asset(
                        isUnfold ? 'assets/images/收起.png' : 'assets/images/展开1.png',
                        width: 14,
                        height: 14,
                      ),
                    ],
                  ),
                ),
                const SizedBox(width: 12),
              ],
            ),

            /// 搜索不到时显示的提示信息
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 2),
              child: Column(
                children: [
                  const SizedBox(height: 25),
                  Image.asset(
                    'assets/images/nosearch.png',
                    width: 160,
                    height: 95,
                  ),
                  const SizedBox(height: 25),
                  Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 40),
                    child: Text(
                      AppLocalizations.of(context)!.noProductFound,
                      style: const TextStyle(fontSize: 16, color: Color(0xFF000000)),
                      textAlign: TextAlign.center,
                    ),
                  ),
                  const SizedBox(height: 20),

                  /// 联系客服按钮
                  SizedBox(
                    width: 140,
                    height: 40,
                    child: ElevatedButton(
                      onPressed: () => clickCustom(),
                      style: ElevatedButton.styleFrom(
                        padding: EdgeInsets.zero,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(20),
                        ),
                        backgroundColor: Colors.transparent,
                        shadowColor: Colors.transparent,
                      ),
                      child: Ink(
                        decoration: BoxDecoration(
                          gradient: const LinearGradient(
                            colors: [Color(0xFF9D26FF), Color(0xFF6426FF)],
                            begin: Alignment.centerLeft,
                            end: Alignment.centerRight,
                          ),
                          borderRadius: BorderRadius.circular(20),
                        ),
                        child: Container(
                          alignment: Alignment.center,
                          child: Text(
                            AppLocalizations.of(context)!.contactCustomer,
                            style: const TextStyle(
                              fontSize: 15,
                              color: Colors.white,
                            ),
                          ),
                        ),
                      ),
                    ),
                  ),
                  const SizedBox(height: 30),

                  /// 白色背景容器
                  Container(
                    margin: const EdgeInsets.symmetric(horizontal: 10),
                    padding: const EdgeInsets.all(20),
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(12),
                    ),
                    child: Stack(
                      children: [
                        /// 右上角图片
                        Positioned(
                          right: 1,
                          top: 1,
                          child: Image.asset(
                            'assets/images/searchnone.png',
                            width: 125,
                            height: 108,
                          ),
                        ),
                        
                        /// 提示文本列表
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            /// 第一行
                            Padding(
                              padding: const EdgeInsets.only(bottom: 10),
                              child: Text(
                                AppLocalizations.of(context)!.noProductFound1,
                                style: const TextStyle(
                                  fontSize: 15,
                                  fontWeight: FontWeight.bold,
                                  color: Color(0xFF31383F),
                                ),
                              ),
                            ),
                            
                            /// 中间三行
                            Padding(
                              padding: const EdgeInsets.only(bottom: 10),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  const Text(
                                    '• ',
                                    style: TextStyle(
                                      fontSize: 13,
                                      color: Color(0xFF666666),
                                    ),
                                  ),
                                  Expanded(
                                    child: Text(
                                      AppLocalizations.of(context)!.noProductFound2,
                                      style: const TextStyle(
                                        fontSize: 13,
                                        color: Color(0xFF666666),
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            
                            Padding(
                              padding: const EdgeInsets.only(bottom: 10),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  const Text(
                                    '• ',
                                    style: TextStyle(
                                      fontSize: 13,
                                      color: Color(0xFF666666),
                                    ),
                                  ),
                                  Expanded(
                                    child: Text(
                                      AppLocalizations.of(context)!.noProductFound3,
                                      style: const TextStyle(
                                        fontSize: 13,
                                        color: Color(0xFF666666),
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            
                            Padding(
                              padding: const EdgeInsets.only(bottom: 10),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  const Text(
                                    '• ',
                                    style: TextStyle(
                                      fontSize: 13,
                                      color: Color(0xFF666666),
                                    ),
                                  ),
                                  Expanded(
                                    child: Text(
                                      AppLocalizations.of(context)!.noProductFound4,
                                      style: const TextStyle(
                                        fontSize: 13,
                                        color: Color(0xFF666666),
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            
                            /// 最后一行带登录按钮
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                const Text(
                                  '• ',
                                  style: TextStyle(
                                    fontSize: 13,
                                    color: Color(0xFF31383F),
                                  ),
                                ),
                                Expanded(
                                  child: Row(
                                    children: [
                                      Expanded(
                                        child: Text(
                                          AppLocalizations.of(context)!.noProductFound5,
                                          style: const TextStyle(
                                            fontSize: 13,
                                            color: Color(0xFF31383F),
                                          ),
                                        ),
                                      ),
                                      const SizedBox(width: 10),
                                      SizedBox(
                                        width: 92,
                                        height: 25,
                                        child: ElevatedButton(
                                          onPressed: () {
                                            // 登录按钮点击事件
                                            Navigator.push(
                                              context,
                                              MaterialPageRoute(builder: (context) => const SetPage()),
                                            );
                                          },
                                          style: ElevatedButton.styleFrom(
                                            backgroundColor: const Color(0xFFF3F3FF),
                                            shape: RoundedRectangleBorder(
                                              borderRadius: BorderRadius.circular(12),
                                            ),
                                            padding: EdgeInsets.zero,
                                            elevation: 0,
                                          ),
                                          child: const Text(
                                            '登录原有账号',
                                            style: TextStyle(
                                              fontSize: 13,
                                              color: Color(0xFF5D5FEE),
                                            ),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                  const SizedBox(height: 20),

                  /// 推荐商品标题
                  Padding(
                    padding: const EdgeInsets.only(left: 20),
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '推荐商品',
                        style: const TextStyle(
                          fontSize: 15,
                          color: Color(0xFF666666),
                        ),
                      ),
                    ),
                  ),

                  const SizedBox(height: 20),

                  /// 👇 新增：noDataList 样式的 Grid
                  GridView.builder(
                    padding: const EdgeInsets.all(10),
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    itemCount: noDataList.length,
                    gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                      crossAxisCount: 3,
                      crossAxisSpacing: 10,
                      mainAxisSpacing: 10,
                      childAspectRatio: 1 / 1.3, // 近似宽:高 = 1:(1+35/宽)
                    ),
                    itemBuilder: (context, index) {
                      final model = noDataList[index];
                      return GestureDetector(
                        onTap: () {
                          // TODO: 点击事件处理，比如跳转详情
                          pushDetail(model.id);
                        },
                        child: LayoutBuilder(
                          builder: (context, constraints) {
                            final itemWidth = constraints.maxWidth;
                            final imageWidth = itemWidth - 50;
                            return Container(
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(15),
                              ),
                              child: Column(
                                children: [
                                  // 图片
                                  Container(
                                    margin: const EdgeInsets.only(top: 15),
                                    alignment: Alignment.center,
                                    child: SizedBox(
                                      width: imageWidth,
                                      height: imageWidth,
                                      child: ClipRRect(
                                        borderRadius: BorderRadius.circular(12),
                                        child: CachedImage(
                                          imageUrl: model.pic,
                                          fit: BoxFit.cover,
                                        ),
                                      ),
                                    ),
                                  ),
                                  // 名称
                                  Container(
                                    margin: const EdgeInsets.only(
                                        top: 12, left: 5, right: 5, bottom: 10),
                                    height: 40,
                                    alignment: Alignment.center,
                                    child: Text(
                                      model.name,
                                      maxLines: 2,
                                      overflow: TextOverflow.ellipsis,
                                      textAlign: TextAlign.center,
                                      style: const TextStyle(
                                        fontSize: 14,
                                        color: Color(0xFF000000),
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            );
                          },
                        ),
                      );
                    },
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    ),
  );
}



}
